// pages/success/success.js
const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    hotPro: {},
    info: {
      product: {
        id: '',
        price: '',
        name: '',
        main_img: '',
        time: '',
        unit: '',
        service_category_id: '',
        content: ''
      },
      address: {
        id: '',
        name: '',
        phone: '',
        address: '',
        province_id: '',
        city_id: '',
        district_id: ''
      },
      time: {
        start_at: '',
        end_at: '',
        hours: 1
      },
      cleaner: {
        id: '',
        wx_avatar_url: '',
        real_name: ''
      },
      coupon: {
        id: '',
        price: '',
      },
      remark: '',
      totalPrice: 0,
      textarea: true
    }
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getHot()
  },

  getHot: function() {
    let that = this
    wx.showLoading({
      mask: true,
      title: '数据加载中',
    })
    app.getAccessToken(app.getPageUrl(getCurrentPages())).then(function (accessToken) {
      wx.request({
        url: app.globalData.hostAPI + '/v1/index?access_token=' + accessToken,
        success: res => {
          if(res.data.status === 1) {
            that.setData({
              hotPro: res.data.data.fast
            })
            wx.hideLoading()
          }
        }
      })
    })
  },

  hotPay: function(e) {
    let _this = this
    
    _this.setData({
      'info.product.id': e.currentTarget.id
    })
    
    wx.reLaunch({
      url: '/pages/product/product?info=' + JSON.stringify(_this.data.info),
    })
  }
})